home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-09-16 | 5.8 KB | 282 lines | [TEXT/CWIE] |
- /*
- White Lines
- ⌐1999, @soft
-
- Description: Simple and NOT COMMENTED visual plugin for MACAST 1.0.
- Version: 1.2
- Released: 7/11/99
- Compatibility: MACAST 1.0
- Version history:
-
- Date Who Changes
- ------+------+------------------------------------------------------
- 071199 SKA Modified to be used with Visual Plugin API 1.2
- 050299 SKA Simple plugin is done.
- */
-
- #include "MACAST_Visual.h"
-
- const OSType kAuthorID = 'exmp'; // Please change the author code to different value to avoid collisions.
- const OSType kPluginID = 'RGBs';
-
- VPInfoBlock gPlugInfo =
- {
- VP_INFOBLOCK_HEADER(kAuthorID, kPluginID),
-
- "\pRGBSpectrum x2",
-
- VisInitialize,
- VisTerminate,
- nil, // we don't idle
- VisAbout,
- VisDraw,
- VisClick,
-
- nil, // we don't want keydowns..
- nil, // ...and events
-
- VisError,
- nil, // we have no settings
- VisTrackBegin,
- VisTrackEnd,
- nil, // no listen proc
-
- // Nifty macro to set all these 'reserved' values for us
- VP_INFOBLOCK_FOOTER
- };
-
- typedef struct
- {
- short num;
- RGBColor color[];
- } Colors, *ColorsPtr, **ColorsHandle;
-
- typedef struct
- {
- UInt16 colorIndex;
- } OwnPrefs, *OwnPrefsPtr;
-
- ColorsHandle gColors;
- RGBColor gCurrColor;
- UInt16 gResFork;
- UInt16 gValues[300];
- UInt8* gFFTArray;
- Rect gRect;
- GWorldPtr gWorld = nil;
- OwnPrefs gPrefs;
- UInt32 gAboutExpire = nil;
- Boolean gAbout = false;
- QDGlobalsPtr gQD;
-
- OSStatus VisInitialize(FSSpecPtr inPlugin, WindowPtr* outWindow, UInt32* ioRefcon)
- {
- OSStatus err;
-
- gResFork = FSpOpenResFile(inPlugin, fsRdPerm);
- gQD = gPlugInfo.ma->GetQDGlobals();
-
- // Get list of colors
- gColors = (ColorsHandle)GetResource('COLR', 128);
- if (!gColors)
- return errVisTerminate;
-
- DetachResource((Handle)gColors);
-
- // Load own preferences
- UInt16 size = sizeof(OwnPrefs);
- err = gPlugInfo.ma->ReadPrefs(kAuthorID, kPluginID, (Ptr)&gPrefs, &size);
- if (err != noErr || size != sizeof(OwnPrefs)) // Preferences can't be read, we need to make a struct and fill
- // it with default values
- {
- gPrefs.colorIndex = nil;
-
- // Save the preferences right away
- gPlugInfo.ma->SavePrefs(kAuthorID, kPluginID, (Ptr)&gPrefs, sizeof(OwnPrefs));
- }
-
- HLock((Handle)gColors);
- if (gPrefs.colorIndex >= (*gColors)->num)
- gPrefs.colorIndex = nil;
- gCurrColor = (*gColors)->color[gPrefs.colorIndex];
- HUnlock((Handle)gColors);
-
- // Aquire FFT array
- gPlugInfo.ma->GetValues(&gFFTArray, &size);
-
- // Create work GWorld
- CGrafPtr savePort;
- GDHandle saveDevice;
-
- SetRect(&gRect, 0, 0, 300, 50);
- err = ::NewGWorld(&gWorld, nil, &gRect, nil, nil, nil);
-
- GetGWorld(&savePort, &saveDevice);
- SetGWorld(gWorld, nil);
- LockPixels(::GetGWorldPixMap(gWorld));
- ForeColor(whiteColor);
- BackColor(blackColor);
- TextFont(21);
- TextSize(12);
- TextFace(bold);
- EraseRect(&gRect);
- UnlockPixels(::GetGWorldPixMap(gWorld));
- SetGWorld(savePort, saveDevice);
-
- for (short i=0;i<300;i++)
- gValues[i] = 0;
-
-
- // Create own window
- *outWindow = NewWindow(nil, &gRect, "\pRGBSpectrum", false, 1985, (WindowPtr)-1, true, nil);
- if (*outWindow == nil)
- return errVisTerminate;
-
- MoveWindow(*outWindow, gQD->screenBits.bounds.right - 320, gQD->screenBits.bounds.bottom - 80, true);
- ShowWindow(*outWindow);
-
- return errVisNoErr;
- }
-
- OSStatus VisTerminate(WindowPtr inWindow, UInt32* ioRefcon)
- {
- // Save preferences
- gPlugInfo.ma->SavePrefs(kAuthorID, kPluginID, (Ptr)&gPrefs, sizeof(OwnPrefs));
-
- DisposeWindow(inWindow);
-
- // Dispose everything we allocated
- if (gWorld)
- DisposeGWorld(gWorld);
-
- if (gColors)
- DisposeHandle((Handle)gColors);
-
- if (gResFork != -1)
- CloseResFile(gResFork);
-
- return errVisNoErr;
- }
-
- OSStatus VisAbout(WindowPtr inWindow, UInt32* ioRefcon)
- {
- gAbout = true;
- gAboutExpire = TickCount() + 360;
- return errVisNoErr;
- }
-
- OSStatus VisDraw(WindowPtr inWindow, UInt32* ioRefcon)
- {
- // Calculate values
- UInt32 timer, status;
- gPlugInfo.ma->GetStatus(&timer, &status);
-
- if (status & statusStopped)
- {
- for (short i=0;i<300;i++)
- gValues[i] = 0;
- }
- else
- {
- for (short i=0, a=4; i<300; i++, a++)
- {
- gValues[i] = gFFTArray[a]/2;
-
- if (gValues[i] > 48)
- gValues[i] = 48;
- }
- }
-
- // Render offscreen
- CGrafPtr savePort;
- GDHandle saveDevice;
-
- GetGWorld(&savePort, &saveDevice);
- SetGWorld(gWorld, nil);
- LockPixels(::GetGWorldPixMap(gWorld));
- BackColor(blackColor);
- EraseRect(&gRect);
-
- // If we have about active, draw it
- if (gAbout)
- {
- if (TickCount() < gAboutExpire)
- {
- ForeColor(whiteColor);
- MoveTo(150, 25);
- DrawString("\pRGBSpectrum");
- MoveTo(200, 38);
- DrawString("\pby slava");
- }
- else
- gAbout = false;
- }
-
- RGBForeColor(&gCurrColor);
- MoveTo(0,50);
- for (short i=0;i<300;i++)
- {
- Line(0, -gValues[i]);
- Move(1, gValues[i]);
- }
-
- // Nice decoration time!
- RGBColor decor = { 50000, 50000, 50000 };
- MoveTo(0, 50);
- PenMode(adMin);
- PenSize(1,2);
- for (short i=0;i<50;i+=2)
- {
- RGBForeColor(&decor);
- MoveTo(0,50-i);
- Line(320,0);
-
- decor.red -= 2000;
- decor.green -= 2000;
- decor.blue -= 2000;
- }
- PenNormal();
-
- SetGWorld(savePort, saveDevice);
-
- // Copy to our window
- GrafPtr oldPort;
- GetPort(&oldPort);
- SetPort(inWindow);
- ::CopyBits(&((GrafPtr)gWorld)->portBits, &inWindow->portBits,
- &gRect,
- &gRect,
- srcCopy, nil);
- UnlockPixels(::GetGWorldPixMap(gWorld));
- SetPort(oldPort);
- return errVisNoErr;
- }
-
- OSStatus VisClick(WindowPtr inWindow, Point inClick, UInt32* ioRefcon)
- {
- // MACAST will handle window drags and goAway clicks for us.
- HLock((Handle)gColors);
- gPrefs.colorIndex++;
- if (gPrefs.colorIndex >= (*gColors)->num)
- gPrefs.colorIndex = nil;
- gCurrColor = (*gColors)->color[gPrefs.colorIndex];
- HUnlock((Handle)gColors);
-
- return errVisNoErr;
- }
-
- Boolean VisError(StringPtr outErrString, OSStatus* outErrNum)
- {
- return false;
- }
-
- OSStatus VisTrackBegin(WindowPtr inWindow, UInt32* ioRefcon)
- {
- return errVisNoErr;
- }
-
- OSStatus VisTrackEnd(WindowPtr inWindow, UInt32* ioRefcon)
- {
- return errVisNoErr;
- }
-
-